package com.ldc.wandroid.viewmodel;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.ldc.common.model.BasePagingModel;
import com.ldc.common.mvvm.ViewModelBase;
import com.ldc.wandroid.model.ArticleItemModel;
import com.ldc.common.net.Api2Request;
import com.ldc.wandroid.server.ApiServer;

public class ProjectInfoViewModel extends ViewModelBase {
    private final ApiServer apiServer;

    public ProjectInfoViewModel() {
        apiServer = Api2Request.getInstance().createServer(ApiServer.class);
    }

    private final MutableLiveData<BasePagingModel<ArticleItemModel>> _projectInfo = new MutableLiveData<>();
    private final MutableLiveData<Boolean> _loading = new MutableLiveData<>(false);

    public LiveData<BasePagingModel<ArticleItemModel>> projectInfo() {
        return _projectInfo;
    }

    public LiveData<Boolean> loading() {
        return _loading;
    }

    public void loadProjectInfo(int index, String cid) {
        apiRequest(apiServer.get_projects_article(index, cid), (status, result, throwable) -> {
            if (result.isSuccess()) {
                _projectInfo.setValue(result.getData());
            } else {
                _projectInfo.setValue(null);
            }
        });
    }


}
